package com.tuanbiao.models.action;

import com.hzjq.data.base.UploadBlastService;
import com.hzjq.data.callback.Callback;
import com.hzjq.data.entity.BlastEntity;
import com.hzjq.data.entity.BlastServiceBean;
import com.hzjq.data.entity.ZbServiceEntity;
import com.hzjq.lib.BlastKool;
import com.hzjq.lib.checker.CheckError;
import com.tuanbiao.data.callback.OnBaseResultCallback;

import java.util.List;

import timber.log.Timber;

/**
 * @author abiao
 * @since 2022/4/24 16:20
 */
public interface UploadAction {
    default void uploadBlast(BlastEntity entity, boolean isUploadError, OnBaseResultCallback<Boolean> callback) {
        BlastKool.Companion.loader().quick().uploadBlast(entity, isUploadError, true, aBoolean -> {
            Timber.i("onSuccess#" + aBoolean);
            callback.onSuccess(aBoolean);
            callback.onFinish();
        });

//        new HttpCallback<Boolean>() {
//            @Override
//            public void onSuccess(Boolean aBoolean) {
//
//            }
//
//            @Override
//            public void onFailed(@NonNull String s) {
//                Timber.i("onFailed#" + s);
//                callback.onFailed(s);
//                callback.onFinish();
//            }
//        }
    }

    default void uploadBlastAll() {

    }

    default List<BlastServiceBean> getAllUploadService() {
        return BlastKool.Companion.loader().getUploadBlastService();
    }

    default void setUploadService(List<BlastServiceBean> serviceBeans) {
        BlastKool.Companion.loader().newSettingBuilder()
                .addUploadService(UploadBlastService.ZHONGBAO, true)
                .setAllUploadService(serviceBeans)
                .build();
    }

    default void queryZbIp(OnBaseResultCallback<List<ZbServiceEntity>> callback) {
        BlastKool.Companion.loader().db().queryZbIp(new Callback<List<ZbServiceEntity>>() {
            @Override
            public void run(List<ZbServiceEntity> zbServiceEntities) {
                callback.onSuccess(zbServiceEntities);
                callback.onFinish();
            }
        });
    }

    default void setNewZbIp(List<ZbServiceEntity> ips, OnBaseResultCallback<Boolean> callback) {
        BlastKool.Companion.loader().db().setNewZbIp(ips, new Callback<Boolean>() {
            @Override
            public void run(Boolean aBoolean) {
                callback.onSuccess(aBoolean);
                callback.onFinish();
            }
        });
    }

    default void selectZbIp(ZbServiceEntity ip, OnBaseResultCallback<Boolean> callback) {
        BlastKool.Companion.loader().db().selectZbIp(ip, new Callback<Boolean>() {
            @Override
            public void run(Boolean aBoolean) {
                callback.onSuccess(aBoolean);
                callback.onFinish();
            }
        });
    }

    default void insertZbIp(ZbServiceEntity ip, OnBaseResultCallback<Boolean> callback) {
        BlastKool.Companion.loader().db().insertZbIp(ip, new Callback<Boolean>() {
            @Override
            public void run(Boolean aBoolean) {
                callback.onSuccess(aBoolean);
                callback.onFinish();
            }
        });
    }

    default void updateZbIp(ZbServiceEntity ip, OnBaseResultCallback<Boolean> callback) {
        BlastKool.Companion.loader().db().updateZbIp(ip, new Callback<Boolean>() {
            @Override
            public void run(Boolean aBoolean) {
                callback.onSuccess(aBoolean);
                callback.onFinish();
            }
        });
    }

    default void removeZBIp() {
        BlastKool.Companion.loader().newSettingBuilder()
                .removeUploadService(UploadBlastService.ZHONGBAO)
                .build();
    }

    default void checkUnUploadCount(OnBaseResultCallback<CheckError> callback) {
        BlastKool.Companion.loader().checker().checkUnUploadCount(new Callback<CheckError>() {
            @Override
            public void run(CheckError checkError) {
                callback.onSuccess(checkError);
                callback.onFinish();
            }
        });
    }
}
